#include "definirmode.h"
#include "ui_definirmode.h"
#include"fenserveur.h"

definirMode::definirMode(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::definirMode)
{
    ui->setupUi(this);
    ui->okButton->setEnabled(false);
    hideWidjet();
    connect(ui->annulerButton, SIGNAL(clicked()), this, SLOT(accept()));
    connect(ui->pseudo, SIGNAL(textEdited(QString)),this,SLOT(buttonOkActiver()));
    connect(ui->okButton, SIGNAL(clicked()), this, SLOT(choixEtabli()));
    connect(ui->mode, SIGNAL(currentIndexChanged(int)), this, SLOT(widjetControl()));
}

definirMode::~definirMode()
{
    delete ui;
}

void definirMode::buttonOkActiver(){
    ui->okButton->setEnabled(true);
}


void definirMode::choixEtabli(){

    if(ui->mode->currentIndex()==0){
        FenServeur *ser = new FenServeur();
        //ser->show();
        DameChinoise *dame = new DameChinoise(this);
        dame->setLabelText(ui->pseudo->text());
        dame->setNumeroPort(ser->numPort);
        dame->on_boutonConnexion_clicked();
        dame->show();
     }
    else{
        DameChinoise *dame = new DameChinoise(this);
        dame->setLabelText(ui->pseudo->text());
        dame->show();
    }
}

void definirMode::hideWidjet(){
    ui->adrIPLabel->hide();
    ui->numPortLabel->hide();
    ui->adrIP->hide();
    ui->numPort->hide();
}

void definirMode::showWidjet(){
    ui->adrIPLabel->show();
    ui->numPortLabel->show();
    ui->adrIP->show();
    ui->numPort->show();
}



void definirMode::widjetControl(){
    if(ui->mode->currentIndex() == 0){
        hideWidjet();

    }
    if(ui->mode->currentIndex() == 1){
        showWidjet();
    }

}

